var photoSwiperObj = {
    el: '#pageApp',
    data: {
       albumId:'',
       hasGetData:false,
       photoSwiperData:{
        photoList:[]
       },
    },
    components:{
      'photo-swiper':photoSwiper,
      'top-tab-bar':topTabBar
    },
    methods: {
      getAlbumItems:function(){
        var _this = this;
        g.ajax({
          type: 'GET',
          url: g.url.format('/api/author/getAlbumItems'),
          data:{albumId: _this.albumId},
          success: function (result) {
             _this.setPhotoList(result.data);   
          }
        });
      },
      setPhotoList:function(data){
        var _this = this;
        var photoList = [];
        console.log(data);
        data.forEach(function (item) {
          var obj = {};
          obj.imgSrc = g.url.imgFormat(item.filename);
          obj.id = item.albumitemid;
          obj.fav = false;
          photoList.push(obj);
        });
        _this.photoSwiperData.photoList = photoList;
        _this.hasGetData = true;
      },
      toggleFav:function(id,index){
        var _this = this, status = 0;
        _this.photoSwiperData.photoList[index].fav = !_this.photoSwiperData.photoList[index].fav;
        if(_this.photoSwiperData.photoList[index].fav){
          status = 1;
        };
        g.ajax({
          type: 'POST',
          url: g.url.format('/api/author/setCommend'),
          data:{relationId:id,relationType:2,status:status},
          success: function (result) {
              if(status == 1){
                g.modal.waiting({title:'已点赞！',icon:'icon-dagou-shi'});
              }else{
                g.modal.waiting({title:'已取消！',icon:'icon-dagou-shi'});
              }
          }
        });
      }

    },
    mounted:function () {
      this.albumId = g.params.get('id'); 
      this.getAlbumItems(); 
    }
};
var initPage = function(){
  new Vue(photoSwiperObj);
};
